home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_200
/
274_01
/
array.art
< prev
next >
Wrap
Text File
|
1980-01-01
|
9KB
|
316 lines
Arrays for C
Article on Arrays for C
Version 1.00
INTRO
Arrays for C version 1.00 is a set of C header files that
simplifies array handling in C. They allow four classes of
operations: unary (on a single array), binary (on multiple
arrays), fill arrays, and information on arrays. They work on
mixed types (including constants), and should work on a wide
range of compilers and computers without modification. The
routines are available as shareware or retail.
OVERVIEW
The routines were written to help me handle arrays in a
uniform manner, and to have a set of canned routines that were
debugged, and capable of doing operations on all kinds of arrays.
The routines are broken up into the following types:
Binary Operations Add, Multiply, etc. 2 arrays/constant
Unary Operations Negate, Assign, Absolute, etc. an array
Fill Operations Fill array with index, values etc.
Info about Array Min, Max, etc. of an array
There are also routines to call a function in each category.
The routines work by substituting your call into a while
loop. This was the ONLY way I could find to use different types
of arrays/constants in an expression that would be compatible
across a wide range of compilers/systems. (I spent 3 months
trying all kinds of different ways, but none would work on ALL of
the compilers I could test with, except this method). The
routines have been tested with multiple compilers including
Microsoft 5.0, Turbo 1.5 and Aztec 3.40B on PC & AT Clones.
USAGE
In order to use the routines, you include the file ARRAY.H in
your program. i.e.:
#include <stdio.h>
#include "array.h"
main()
{
.
.
.
Then use the routines whenever/wherever you need them.
James P. Cruse, Sci-Pic
919 Capitola Ave, Suite 41, Capitola, CA 95010
(408) 475-7444
Arrays for C
Article on Arrays for C
Version 1.00
USAGE (continued)
The Functions all have a uniform naming format:
X_NAME, where X is:
a for single array operations
aa for multiple array operations
ac for array & constant,
and ca for constant & array
And NAME is the operation to be done.
For Example:
aa_add() add two arrays
ac_add() add array & constant
a_neg() negate array
a_index() fill array with index
TEST/EXAMPLES
There are example routines included. There is both an integer
and a float example: A_testf.c does a floating point example,
proving numerically sin^2+cos^2=1; and a_testi does an integer
example, showing the sum of an arithmetic sequence is a simple
calculation.
CUSTOMIZATION OPTIONS
There are a few #defines used to select compiler dependent
options: does the compiler allow curly braces without a
proceeding if or while, and for taking the Min and Max of two
elements.
There are also #defines selecting which routines to link in
by default (which you can override at include time), and what
variable name and type to use for the loop variable.
James P. Cruse, Sci-Pic
919 Capitola Ave, Suite 41, Capitola, CA 95010
(408) 475-7444
Arrays for C
Article on Arrays for C
Version 1.00
QUICK SUMMARY
The following is a quick description of the operations available.
Remember to prepend the a_,aa_,ac_,ca_ to the name depending on
the parameters to the operation. Each list is followed by an
example of a couple of the functions.
Binary Operations: (a_binop.h)
add, sub, mul, div, min, max, mod (%,modulo),
equ (==), geq (>=), leq (<=), gtr (>), les (<),
fun (function), t_fun (typed function)
aa_add(n,d,a,b) d[] = a[] + b[]
ac_min(n,d,a,c) d[] = ARR_MIN(a[],c)
ca_sub(n,d,c,a) d[] = c - a[]
aa_fun(n,d,a,b,f) d[] = f(a[],b[])
ac_t_fun(n,d,a,c,f,t) d[] = f( (t) a[] , (t) c )
Unary Operations: (a_unop.h)
cpy (copy,assign), neg (negate), abs (absolute value),
rsum (running sum), rprod (running product),
rmin (running min), rmax (running max),
fun (function), t_fun (typed function)
scale (scale&offset)
a_cpy(n,d,a) d[] = a[]
a_rsum d[i] = d[i-1] + a[i]
a_rmax d[i] = ARR_MAX( d[i-1] , a[i] )
a_scale(n,d,a,s,o) d[] = o + s*a[]
a_fun(n,d,a,f) d[] = f(a[])
a_t_fun(n,d,a,f,t) d[] = (t) f( (t) a[] )
Info Operations: (a_info.h)
sum, prod, min, max, minmax
a_sum(n,d,a) d = a[0] + a[1] + ... + a[n-1]
a_min(n,d,a) d = min( a[0] , ... , a[n-1] )
a_minmax(n,l,u,a) l = min( a[0] , ... , a[n-1] ),
and u = max( a[0] , ... , a[n-1] )
James P. Cruse, Sci-Pic
919 Capitola Ave, Suite 41, Capitola, CA 95010
(408) 475-7444
Arrays for C
Article on Arrays for C
Version 1.00
QUICK SUMMARY (continued)
Fill Operations: (a_fill.h)
index, indoff (index+offset), fill (exclusive),
ifill (inclusive), t_fill (typed exclusive fill),
t_ifill (typed inclusive fill)
scale (scale&offset),
assign, f_fun (function), i_fun, (function w/index param),
t_i_fun (typed function w/index param)
a_indoff(n,d,c) d[i] = i + c
a_assign(n,d,c) d[] = c
a_i_scale(n,d,s,o) d[i] = s*i + o
a_fill(n,d,s,e) d[0] = s, d[i] = s+(e-s)/n,
d[n] (would be) e
a_t_ifill(n,d,s,e) d[0] = s,
d[i] = s+((t)(e-s))/(n-1),
d[n-1] = e
a_f_fun(n,d,f) d[] = f()
a_t_i_fun(n,d,f,t) d[i] = f( (t) i )
James P. Cruse, Sci-Pic
919 Capitola Ave, Suite 41, Capitola, CA 95010
(408) 475-7444
Arrays for C
Article on Arrays for C
Version 1.00
I hope you will try the routines, and find them of use. If
there are any questions